<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layui-form layuimini-form layui-form-pane">
    <input type="hidden" name="canuselevel" value="{$canuselevel}">
    <input type="hidden" name="title" value="{$title}">
    <input type="hidden" name="industry_id" value="{$industry_id}">
    <input type="hidden" name="min_worth" value="{$min_worth}">
    <input type="hidden" name="max_worth" value="{$max_worth}">
    <div class="layui-form-item" style="display: flex;justify-content: space-between">
        <h2 style="margin-bottom:20px;">行业名称：{$title}</h2>
        <h2 style="margin-bottom:20px;">最小价值：{$min_worth}</h2>
        <h2 style="margin-bottom:20px;">最大价值：{$max_worth}</h2>

    </div>
    <div id="form-content">
        <!--<div class="layui-form-item" style="border:solid 1px #000000;position: relative" >-->
            <!--<div class="layui-form-item" style="margin:10px;">-->
                <!--<label class="layui-form-label required">玩家名称</label>-->
                <!--<div class="layui-input-inline">-->
                    <!--<input type="text" readonly value="" autocomplete="off" class="layui-input">-->
                <!--</div>-->
                <!--<label class="layui-form-label">玩家ID</label>-->
                <!--<div class="layui-input-inline">-->
                    <!--<input type="text" name="member_code[]" value="" readonly autocomplete="off" class="layui-input">-->
                <!--</div>-->
                <!--<label class="layui-form-label required">玩家手机号</label>-->
                <!--<div class="layui-input-inline">-->
                    <!--<input type="number" readonly value="" autocomplete="off" class="layui-input">-->
                <!--</div>-->
                <!--<label class="layui-form-label">投放金额</label>-->
                <!--<div class="layui-input-inline">-->
                    <!--<input type="number" name="earnings_price[]" min="{$min_worth}" max="{$max_worth}"  placeholder="请输入行业金额" autocomplete="off" class="layui-input">-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="layui-form-item" style="margin:10px;">-->
                <!--<label class="layui-form-label">投放数量</label>-->
                <!--<div class="layui-input-inline">-->
                    <!--<input type="number" name="lanunch_num[]" min="1" placeholder="请输入投放数量" autocomplete="off" class="layui-input">-->
                <!--</div>-->
                <!--<label class="layui-form-label required">投放团队</label>-->
                <!--<div class="layui-input-inline">-->
                    <!--<input type="hidden" name="team_id[]">-->
                    <!--<input type="text" placeholder="选择投放团队" autocomplete="off" readonly class="layui-input" id="team1">-->
                <!--</div>-->
                <!--<label class="layui-form-label required">剩余栏位数</label>-->
                <!--<div class="layui-input-inline">-->
                    <!--<input type="number" name="plurs_grid[]" placeholder="可匹配剩余栏位数" autocomplete="off" class="layui-input">-->
                <!--</div>-->
                <!--<label class="layui-form-label required">是否优先</label>-->
                <!--<div class="layui-input-inline" style="border:solid 1px #e2e2e2">-->
                    <!--<input type="radio" name="precedence[]" value="1" title="是" checked="">-->
                    <!--<input type="radio" name="precedence[]" value="2" title="否">-->
                <!--</div>-->
            <!--</div>-->
            <!--<button class="layui-btn layui-btn-danger" onclick="deleteItem(this)" style="position: absolute;top:30%;right:10px;">删除</button>-->
        <!--</div>-->
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-radius" onclick="addmember()">添加投放用户</button>
            <button class="layui-btn layui-btn-radius layui-btn-danger" lay-submit lay-filter="saveBtn">保存并参与匹配</button>
        </div>
    </div>
</div>
<script type="text/html" id="categoryTpl">
    {{#  if(d.category === 1){ }}
    <span > 普通行业</span>
    {{# }else if(d.category === 2){ }}
    <span style="color: #f59b28;">体验行业</span>
    {{#  } else { }}
    <span style="color: #f42540;">集成行业</span>
    {{#  } }}
</script>
{include file="public/footer" /}
<script>
    var form;
    var tableSelect;
    layui.use(['form', 'laydate', 'tableSelect', 'layarea', 'upload'], function (exports) {
        var layer = layui.layer,
            $ = layui.$;
            form = layui.form;
            tableSelect = layui.tableSelect;
            addmember();
        /*创建行业*/
        tableSelect.render({
            elem: '#industry',
            searchKey: 'title',
            checkedKey: 'id',
            searchPlaceholder: '名称搜索',
            table: {
                url: '/admin/Industry/Index?action=ajax',
                method: 'post',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data, //解析数据列表
                    };
                },
                cols: [[
                    {type: 'radio'},
                    {field: 'title', title: '名称'},
                    {field: 'category', title: '类型' ,templet:"#categoryTpl"},
                    {field: 'level', title: '所属等级', sort: true},
                    {field: 'min_worth', title: '基础价值'},
                    {field: 'max_worth', title: '最高价值'},
                ]],
                page: true,
                limits: [10, 15, 20, 25, 30, 50, 100],
                limit: 10
            },
            done: function (elem, data) {
                var NEWJSON = [];
                var industryIdHidden = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.title);
                    $('#industryIdHidden').val(item.id)
                })
                elem.val(NEWJSON.join(","))
            }
        });
        /*选择投放团队*/
        tableSelect.render({
            elem: '#team1',
            searchKey: 'title',
            checkedKey: 'id',
            searchPlaceholder: '名称搜索',
            table: {
                url: '/admin/Member/teamInfo?action=ajax',
                method: 'post',
                parseData: function (res) { //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.data, //解析数据列表
                    };
                },
                cols: [[
                    {type: 'checkbox'},
                    {field: 'title', title: '团队名称', sort: true},
                    {field: 'team_num', title: '团队人数', sort: true},
                    {field: 'income', title: '团队总收益', sort: true},
                ]],
                page: true,
                limits: [10, 15, 20, 25, 30, 50, 100],
                limit: 10
            },
            done: function (elem, data) {
                // var NEWJSON = [];
                // var teamHidden = [];
                // layui.each(data.data, function (index, item) {
                //     NEWJSON.push(item.title)
                //     teamHidden.push(item.id)
                // })
                // elem.val(NEWJSON.join(","))
                // $('#teamIdHidden').val(teamHidden.join(","))
            }
        });
        //监听提交
        var min="{$min_worth}"
            max="{$max_worth}";
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/admin/TransactionData/bentch_lanunch?active=ajax',
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (res) {
                    if (res.status == true) {
                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function () {
                    layer.msg("报错了");
                }
            });
            return false;
        });

    });
    function addmember(){
        layer.prompt({title: '输入玩家ID/手机号', formType: 0}, function (searchInfo, index) {
            layer.close(index);
            $.ajax({
                url: '/admin/transactionData/searchMemberInfo',
                type: 'post',
                dataType: 'json',
                async: false,
                data: {searchInfo: searchInfo},
                success: function (res) {
                    if (res.status == true) {
                        addElement(res.memberInfo.name,res.memberInfo.code,res.memberInfo.phone);
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function () {
                    layer.msg("报错了");
                }
            });
        });
    }
    var num=0;
    function addElement(name,code,phone)
    {
        num++;
        $("#form-content").append("<div class=\"layui-form-item\" style=\"border:solid 1px #000000;position: relative\" >\n" +
            "            <div class=\"layui-form-item\" style=\"margin:10px;\">\n" +
            "                <label class=\"layui-form-label required\">玩家名称</label>\n" +
            "                <div class=\"layui-input-inline\">\n" +
            "                    <input type=\"text\" name='name[]' readonly value=\""+name+"\" autocomplete=\"off\" class=\"layui-input\">\n" +
            "                </div>\n" +
            "                <label class=\"layui-form-label\">玩家ID</label>\n" +
            "                <div class=\"layui-input-inline\">\n" +
            "                    <input type=\"text\" name=\"member_code[]\" value=\""+code+"\" readonly autocomplete=\"off\" class=\"layui-input\">\n" +
            "                </div>\n" +
            "                <label class=\"layui-form-label required\">玩家手机号</label>\n" +
            "                <div class=\"layui-input-inline\">\n" +
            "                    <input type=\"number\" name='phone[]' readonly value=\""+phone+"\" autocomplete=\"off\" class=\"layui-input\">\n" +
            "                </div>\n" +
            "                <label class=\"layui-form-label\">投放金额</label>\n" +
            "                <div class=\"layui-input-inline\">\n" +
            "                    <input type=\"number\" name=\"earnings_price[]\" min=\"{$min_worth}\" max=\"{$max_worth}\"  placeholder=\"请输入行业金额\" autocomplete=\"off\" class=\"layui-input\">\n" +
            "                </div>\n" +
            "            </div>\n" +
            "            <div class=\"layui-form-item\" style=\"margin:10px;\">\n" +
            "                <label class=\"layui-form-label\">投放数量</label>\n" +
            "                <div class=\"layui-input-inline\">\n" +
            "                    <input type=\"number\" name=\"lanunch_num[]\" value='1' min=\"1\" lay-verify=\"required\" placeholder=\"请输入投放数量\" autocomplete=\"off\" class=\"layui-input\">\n" +
            "                </div>\n" +
            "                <label class=\"layui-form-label required\">投放团队</label>\n" +
            "                <div class=\"layui-input-inline\">\n" +
            "                    <input type=\"hidden\" name=\"team_id[]\" id='teamHidden"+num+"'>\n" +
            "                    <input type=\"text\" placeholder=\"选择投放团队\" autocomplete=\"off\" onclick='chooseTeam("+num+")'  readonly class=\"layui-input team\" id=\"team"+num+"\">\n" +
            "                </div>\n" +
            "                <label class=\"layui-form-label required\">剩余栏位数</label>\n" +
            "                <div class=\"layui-input-inline\">\n" +
            "                    <input type=\"number\" name=\"plurs_grid[]\" placeholder=\"剩余栏位数\" autocomplete=\"off\" class=\"layui-input\">\n" +
            "                </div>\n" +
            "                <label class=\"layui-form-label required\">是否优先</label>\n" +
            "                <div class=\"layui-input-inline\" style=\"border:solid 1px #e2e2e2\">\n" +
            "                    <input type=\"radio\" name=\"precedence["+(num-1)+"]\" value=\"1\" title=\"是\" checked=\"\">\n" +
            "                    <input type=\"radio\" name=\"precedence["+(num-1)+"]\" value=\"2\" title=\"否\">\n" +
            "                </div>\n" +
            "            </div>\n" +
            "            <button class=\"layui-btn layui-btn-danger\" onclick=\"deleteItem(this)\" style=\"position: absolute;top:30%;right:10px;\">删除</button>\n" +
            "        </div>");
        form.render();
    }
    // 删除元素
    function deleteItem(obj)
    {
        $(obj).parent().remove();
    }

    function chooseTeam(id)
    {
        var index = layer.open({
            title: '选择团队',
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['100%', '100%'],
            content: '/admin/transactionData/choose_team?id='+id,
        });
        $(window).on("resize", function () {
            layer.full(index);
        });
    }
</script>
</body>
</html>